<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <el-form :model="form" ref="form" :rules="rules" :inline="true" label-position="left" label-width="80px" size="medium">
          <el-form-item label="粽子类型" prop="zongziType">
            <el-select v-model="form.zongziType" class="width250" placeholder="请选择粽子类型">
              <el-option label="如意粽子" value="0"></el-option>
              <el-option label="吉祥粽子" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="账户名" prop="username">
            <el-input v-model="form.username" type="text" placeholder="请输入账户名" class="width250"></el-input>
          </el-form-item>
          <el-form-item label="奖品" prop="rewardId">
            <el-select v-model="form.rewardId" class="width250" :disabled="rewardDisableFlag"  placeholder="请选择奖品">
              <el-option v-for="(item,index) in rewardList" :label="item.name" :value="item.id" :key="index"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <span slot="footer" class="dialog-footer">
       <el-button size="medium" @click="cancel" class="width100 assign-prize-cancle">取 消</el-button>
       <el-button size="medium" type="primary" @click="save" class="width100">确 定</el-button>
    </span>
  </div>
</template>

<script>
import { form } from '@/build';
import { addAssignRiceDumplingRewardList } from '@/services/api/activity';
import rewardList from './reward';

export default {
  name: 'assignPrizeDialog',
  mixins: [form],
  data() {
    return {
      form: {
        zongziType: '',
        username: '',
        rewardId: '',
      },
      rewardList: [],
      rewardDisableFlag: true,
      rules: {
        zongziType: [
          { required: true, message: '请选择粽子类型', trigger: 'blur' },
        ],
        username: [
          { required: true, message: '请输入账户名', trigger: 'blur' },
        ],
        rewardId: [
          { required: true, message: '请选择奖品', trigger: 'blur' },
        ],
      },
    };
  },
  mounted() {
    this.bindSave(addAssignRiceDumplingRewardList, 'saveForm', 'form', {
      afterSuccess: () => {
        this.cancel();
        this.$emit('refresh');
      },
    });
  },
  watch: {
    'form.zongziType': function (val) {
      this.form.rewardId = '';
      if (val !== '') {
        this.rewardDisableFlag = false;
        this.rewardList = rewardList[val];
      }
    },
  },
  methods: {
    save() {
      this.doSave({ action: 'saveForm', form: 'form' });
    },
    cancel() {
      this.$emit('input', false);
    },
  },
};
</script>

<style lang="scss" scoped>
  .app-container{
    text-align: center;
  }
.width250{
  width: 250px;
}
  .width100{
    width: 100px;
  }
  .assign-prize-cancle{
    margin: 10px 40px 0 0;
  }
</style>
